package com.lonely.web.controller.purchase;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lonely.common.core.domain.Select;
import com.lonely.common.core.domain.StatusInfo;
import com.lonely.common.core.domain.api.R;
import com.lonely.purchase.domain.dto.materialpurchase.GoMaterialPurchaseDTO;
import com.lonely.purchase.domain.dto.materialpurchase.QueryMaterialPurchasePageDTO;
import com.lonely.purchase.domain.dto.materialpurchase.RecycledMaterialsDTO;
import com.lonely.purchase.domain.vo.materialpurchase.QueryMaterialPurchasePageVO;
import com.lonely.purchase.service.IMaterialPurchaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : 黄志标
 * @date: 2025/7/21 9:30
 * @description: 物料采购请求处理器
 */
@RestController
@RequestMapping("/purchaseManager/materialPurchase")
@Api(tags = "采购管理/物料采购")
public class MaterialPurchaseController {

    @Autowired
    private IMaterialPurchaseService materialPurchaseItemService;

    /**
     * 分页查询
     *
     * @param queryDto
     * @return
     */
    @PostMapping("/page")
    @ApiOperation(value = "物料采购分页查询")
    public R<Page<QueryMaterialPurchasePageVO>> page(@RequestBody @Validated QueryMaterialPurchasePageDTO queryDto) {
        return R.data(this.materialPurchaseItemService.page(queryDto));
    }

    /**
     * 获取物料采购状态信息
     *
     * @param queryDto
     * @return
     */
    @PostMapping("/getStatusInfo")
    public R<List<StatusInfo>> getStatusInfo(@RequestBody @Validated QueryMaterialPurchasePageDTO queryDto) {
        return R.data(this.materialPurchaseItemService.getStatusInfo(queryDto));
    }


    /**
     * 获取采购供应商下拉列表
     *
     * @param supplierName
     * @return
     */
    @PostMapping("/getPurchaseSupplierSelects")
    public R<List<Select>> getPurchaseSupplierSelects(@RequestParam(value = "supplierName", required = false) String supplierName) {
        return R.data(this.materialPurchaseItemService.getPurchaseSupplierSelects(supplierName));
    }

    /**
     * 采购
     *
     * @param goMaterialPurchases
     * @return
     */
    @PostMapping("/goPurchase")
    @SaCheckPermission("purchase:materialPurchase:goPurchase")
    public R<Boolean> goPurchase(@RequestBody @Validated List<GoMaterialPurchaseDTO> goMaterialPurchases) {
        this.materialPurchaseItemService.goPurchase(goMaterialPurchases);
        return R.status(true);
    }

    /**
     * 回料
     *
     * @param recycledMaterialsDTO
     * @return
     */
    @PostMapping("/recycledMaterials")
    @SaCheckPermission("purchase:materialPurchase:recycledMaterials")
    public R<Boolean> recycledMaterials(@RequestBody @Validated RecycledMaterialsDTO recycledMaterialsDTO) {
        this.materialPurchaseItemService.recycledMaterials(recycledMaterialsDTO);
        return R.status(true);
    }

    /**
     * 获取物料采购单位
     *
     * @param id
     * @return
     */
    @GetMapping("/getMaterialPurchaseUnit/{id}")
    public R<String> getMaterialPurchaseUnit(@PathVariable("id") Long id) {
        return R.data(this.materialPurchaseItemService.getMaterialPurchaseUnit(id));
    }

    /**
     * 通知裁床
     *
     * @param id
     * @return
     */
    @GetMapping("/notifyCuttingBed/{id}")
    @SaCheckPermission("purchase:materialPurchase:notifyCuttingBed")
    public R<Boolean> notifyCuttingBed(@PathVariable("id") Long id) {
        this.materialPurchaseItemService.notifyCuttingBed(id);
        return R.status(true);
    }

}
